package com.dianrui.moonfire.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.dianrui.moonfire.Constant;
import com.dianrui.moonfire.R;
import com.dianrui.moonfire.util.JsonUtils;
import com.dianrui.moonfire.okhttp.XHttpRequest;
import com.dianrui.moonfire.util.StringUtils;
import com.dianrui.moonfire.util.ToastUtil;
import com.dianrui.moonfire.util.Url;
import com.google.gson.JsonObject;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description:我的消息详情
 * User: luoziyin
 * Date: 2020-8-17
 */
public class MessageDeatilsActivity extends BaseActivity {
    private String mMessageId;

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.art_title)
    TextView artTitle;
    @BindView(R.id.art_time)
    TextView artTime;
    @BindView(R.id.art_content)
    TextView artContent;


    @Override
    public int getContentViewId() {
        return R.layout.activity_messagedetails;
    }

    @Override
    public void initView() {
        customInit(true);
        title.setText(getString(R.string.msg_details));
        if (getIntent() != null && getIntent().getExtras()!=null) {
            Bundle bundle = getIntent().getExtras();
            if (bundle != null) {
                mMessageId=bundle.getString("id");
            }
        }
        getMsgDetails();
    }

    @Override
    public void initData() {}



    private void getMsgDetails(){
        JsonObject jsonObject=new JsonObject();
        if (!StringUtils.isEmpty(SPUtils.getInstance().getString("member_id"))) {
            jsonObject.addProperty("member_id", SPUtils.getInstance().getString("member_id"));
        }
        jsonObject.addProperty("messages_id",mMessageId);
        XHttpRequest.getInstance().postRequests(Url.MESSAGEINFO, jsonObject.toString(), new XHttpRequest.XCallBack() {
            @Override
            public void onResponse(String response) throws JSONException {
                if (!StringUtils.isEmpty(response)) {
                        JSONObject jsonObject = new JSONObject(response);
                        if (null != jsonObject &&!isFinishing()) {
                            if (Constant.DATASUCCESS.equals(jsonObject.optString("status"))) {
                                String data = JsonUtils.getJsonStr(response, "data");
                                artTitle.setText(JsonUtils.getJsonStr(data, "title"));
                                artTime.setText(JsonUtils.getJsonStr(data, "create_time"));
                                artContent.setText(JsonUtils.getJsonStr(data, "contents"));
                            }else {
                                ToastUtil.showToast(jsonObject.optString("message"));
                            }
                        }

                }
            }

            @Override
            public void failedRequest(String result) {
                ToastUtil.showToast(getString(R.string.net_error));
            }
        });
    }




    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
